package com.whh.starter.config;

import org.springframework.http.HttpStatus;

public enum DefaultCodeMapper implements CodeMapper{
    /**
     * 成功
     */
    SUCCESS(1, HttpStatus.OK),
    /**
     * 未识别错误
     */
    UNEXPECTED_ERROR(2, HttpStatus.INTERNAL_SERVER_ERROR),

    PARAM_ERROR(3, HttpStatus.BAD_REQUEST),
    SECRET_KEY_PARAM_ERROR(4, HttpStatus.BAD_REQUEST),
    ;


    public static DefaultCodeMapper getInstanceByCode(int code) {
        for (DefaultCodeMapper instance : DefaultCodeMapper.values()) {
            if (instance.getCode() == code) {
                return instance;
            }
        }
        return null;
    }

    DefaultCodeMapper(int code, HttpStatus status) {
        this.code = code;
        this.status = status;
    }

    private final int code;

    private final HttpStatus status;

    @Override
    public int getCode() {
        return code;
    }


    @Override
    public HttpStatus getStatus() {
        return status;
    }
}
